import {
  getBalance
} from "../../api/user/user"
import { moneyFormat } from "../../utils/common"
import { showModal } from "../../utils/modal"

Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 显示金额
    money: 0
  },

  onShow() {
    this.updateTabBarIndex();
    this.getAmountBalance();
  },

  updateTabBarIndex() {
    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      this.getTabBar().setData({
        selected: 4
      })
    }
  },

  // 获取账户余额
  getAmountBalance() {
    getBalance().then(res => {
      this.setData({
        money: moneyFormat(res.data)
      })
    }).catch(err => {
      console.error(err);
    })
  },

  goHistoryList() {
    showModal("暂时没有历史功能")
    // wx.navigateTo({
    //   url: '/pages/history/history',
    // })
  },

  goStarList() {
    showModal("暂时没有收藏功能")
    // wx.navigateTo({
    //   url: '/pages/star/star',
    // })
  },

  goAmountPage() {
    wx.navigateTo({
      url: '/pages/amount/amount',
    })
  }
})